package com.unnison.demo.client.styler;

import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.user.client.ui.Widget;

public class StylerImpl implements Styler {

    Element element;

    @Override
    public String getBackgroundColor() {
        return element.getStyle().getBackgroundColor();
    }

    @Override
    public void setBackgroundColor(String color) {
        element.getStyle().setBackgroundColor(color);
    }

    @Override
    public void setFontSizePx(double value) {
        element.getStyle().setFontSize(value, Unit.PX);
    }

    @Override
    public void setTarget(Object target) {
        if (target instanceof Widget) {
            element = ((Widget) target).getElement();
        } else if (target instanceof Element) {
            element = (Element) target;
        } else {
            assert false : "Invalid element type '" + target.getClass().getName() + "' for Styler";
        }
    }

    @Override
    public void setVisibility(Visibility visibility) {
        element.getStyle().setVisibility(visibility);
    }

    @Override
    public void setMarginTop(int size, Unit unit) {
        element.getStyle().setMarginTop(size, unit);
    }
}
